package storage

import (
	"strings"
)

const (
	CSV   string = "csv"  // csv文件
	EXCEL string = "xlsx" // excel文件
	TXT   string = "txt"  // txt文件
	SQL   string = "sql"  // sql文件
)

type StorageFile struct {
	Path   string
	Name   string
	Format string
	keys   []string
}

func NewStorageFile(path, name string, keys []string) *StorageFile {
	split := strings.Split(name, ".")
	return &StorageFile{
		Path:   path,
		Name:   name,
		Format: split[1],
		keys:   keys,
	}
}

func (s *StorageFile) Write(data <-chan map[string]interface{}) {
	NewFactory(s.Format, s.Name, s.Path).WriteDataToFile(data, s.keys)
}
